#include "plane.h"
#include "scene.h"


Plane::Plane()
{
    plane_picture.load(":/images/plane");
    //图片初始化
    plane_x=(scene_width-plane_picture.width())/2;
    plane_y=scene_height-plane_picture.height();
    //飞机坐标初始化，位于底部中央
    plane_spuare.setWidth(plane_picture.width());
    plane_spuare.setHeight(plane_picture.height());
    plane_spuare.moveTo(plane_x,plane_y);
    //画出矩形边框，并移动到飞机所在位置
}

void Plane::shoot()
{
    bullet_recorder++;
    //累加时间间隔
    if(bullet_recorder>=30){
        bullet_recorder=0;
        for(int i=0;i<100;i++){
            if(bullets[i].bullet_situation){
                bullets[i].bullet_situation=false;
                bullets[i].bullet_x=plane_x+plane_picture.width()/2;
                bullets[i].bullet_y=plane_y;
                break;
            }
            //选取空闲的子弹进行发射
        }
    }
    //每次累积到30ms为一次发射时间
}

void Plane::newplane(int x,int y)
{
    plane_x=x;
    plane_y=y;
    plane_spuare.moveTo(x,y);
}
